package net.lab1024.sa.admin.module.business.amount.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.amount.dao.AmountDao;
import net.lab1024.sa.admin.module.business.amount.domain.entity.AmountEntity;
import net.lab1024.sa.admin.module.business.amount.domain.form.AmountAddForm;
import net.lab1024.sa.admin.module.business.amount.domain.form.AmountQueryForm;
import net.lab1024.sa.admin.module.business.amount.domain.form.AmountUpdateForm;
import net.lab1024.sa.admin.module.business.amount.domain.vo.AmountVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 钱包表 Service
 *
 * @Author syf
 * @Date 2025-05-29 15:15:31
 * @Copyright 畅想科技
 */

@Service
public class AmountService {

    @Resource
    private AmountDao amountDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<AmountVO> queryPage(AmountQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<AmountVO> list = amountDao.queryPage(page, queryForm);
        PageResult<AmountVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(AmountAddForm addForm) {
        AmountEntity amountEntity = SmartBeanUtil.copy(addForm, AmountEntity.class);
        amountDao.insert(amountEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     * @param updateForm
     * @return
     */
    public ResponseDTO<String> update(AmountUpdateForm updateForm) {
        AmountEntity amountEntity = SmartBeanUtil.copy(updateForm, AmountEntity.class);
        amountDao.updateByUserId(amountEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    public ResponseDTO<String> batchDelete(List<Integer> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        amountDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Integer id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        amountDao.deleteById(id);
        return ResponseDTO.ok();
    }
}
